package com.com.ruanmeng.view;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.KeyEvent;


@SuppressWarnings("unused")
public class PopupWindowUpdateUtils {
	private PopupYearWindowCallBack callBack;
	private Context activity;
	private static PopupWindowUpdateUtils popupWindowPrivinceListUtils;
	public static synchronized PopupWindowUpdateUtils getInstance(){
		if(popupWindowPrivinceListUtils==null){
			popupWindowPrivinceListUtils = new PopupWindowUpdateUtils();
		}
		return popupWindowPrivinceListUtils;
	}
	public void getSmartUpdateDialog(Context context, String content, String title, final PopupYearWindowCallBack callBack){
		activity = context;
		this.callBack = callBack;
		AlertDialog.Builder builer = new AlertDialog.Builder(activity);
		if (true) {
			builer.setTitle("检测到有新版本，请更新吧");
			builer.setMessage("新版本上线了，速度下载体验吧！");
			builer.setPositiveButton("确定", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
                callBack.doWork();
				}
			});
		} else {
			builer.setTitle("恭喜你！");
			builer.setMessage("当前为最新版本！！");
		}
		AlertDialog dialog = builer.create();
		dialog.setCancelable(false);
		dialog.setCanceledOnTouchOutside(false);
		dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
			@Override
			public boolean onKey(DialogInterface dialogInterface, int keycode, KeyEvent keyEvent) {
				if ((keycode == KeyEvent.KEYCODE_HOME)) {
					return true;
				} else {
					return false;
				}
			}
		});
		dialog.show();
	}

	public void getUpdateDialog(Context context,final PopupYearWindowCallBack callBack){
		activity = context;
		this.callBack = callBack;
		AlertDialog.Builder builer = new AlertDialog.Builder(activity);
		if (true) {
			builer.setTitle("有新版本，是否更新？");
			builer.setMessage("新版本上线了，赶紧下载体验吧！");
			builer.setPositiveButton("确定", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
                callBack.doWork();
				}
			});
		} else {
			builer.setTitle("恭喜你！");
			builer.setMessage("当前为最新版本！！");
		}
		builer.setNeutralButton("忽略", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		});
		AlertDialog dialog = builer.create();
		dialog.show();
	}

	public static interface PopupYearWindowCallBack {
		public void doWork();
		public void doBack();
	}

	}




